package celiasoft.itasalib.query.utility;

import android.os.AsyncTask;
import android.util.Log;
import celiasoft.itasalib.query.Query;
import celiasoft.itasalib.query.result.QueryResult;

public class QueryTask extends AsyncTask<Query, Void, QueryResult> {
	
	private static final String TAG = "itasalib.query.utility.QueryTask";
	private IQueryTaskListener _listener;
	
	public QueryTask(IQueryTaskListener listener) {
		super();
		this._listener = listener;
	}

	@Override
	protected QueryResult doInBackground(Query... query) {
		
		QueryResult result = query[0].execute();
		Log.i(TAG, "Status of result call is " + result.getStatusType());
	
		return result;
		
        
	}

	
	@Override
	protected void onPostExecute(QueryResult result) {
		super.onPostExecute(result);
		
		if(result != null && this._listener != null)
			this._listener.onComplete(result);
		
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		
		if(this._listener != null)
			this._listener.onStartTask();
	}

}
